<!-- 学生端主界面 -->
<template>
	<view class="shop-home-page">
		<!-- 顶部蓝色背景 -->
		<view class="top-section">
			<view class="search-bar-top">
				<u-search class="u-search-custom" v-model="search" :showAction="true" actionText="搜索" @search="onSearch"
					@custom="onSearch" placeholder="请输入商品名称" bgColor="#fff" height="32" :animation="false" shape="round"
					inputStyle="font-size:14px;" style="border-radius: 20px;"></u-search>
			</view>
		</view>
		<!-- 内容区，白色圆角，固定底部 -->
		<view class="main-section">
			<!-- 左侧分类栏 -->
			<view class="category-bar">
				<view v-for="(tab, idx) in tabList" :key="idx"
					:class="['category-item', current === idx ? 'active' : '']" @click="onTabChange(idx)">
					{{ tab.name }}
				</view>
			</view>
			<!-- 右侧内容区 -->
			<view class="content-bar">
				<!-- 商品列表 -->
				<scroll-view class="goods-scroll" scroll-y>
					<view class="goods-list">
						<view v-for="(item, idx) in goods" :key="idx">
							<view class="goods-card">
								<image class="goods-img" :src="item.image" mode="aspectFill" />
								<view class="goods-side">
									<view class="goods-title">{{ item.name }}</view>
									<view class="goods-price">¥ {{ item.price }}</view>
									<u-button class="buy-btn" type="primary" size="mini" shape="circle"
										customStyle="width:60px;height:24px;font-size:13px;padding:0;"
										@click="goToDetail(item)">
										抢购
									</u-button>
								</view>
							</view>
							<view class="goods-divider"></view>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
		<tabBar></tabBar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				search: '',
				current: 0,
				tabList: [{
						name: '电子产品'
					},
					{
						name: '家用电器'
					},
					{
						name: '服饰箱包'
					}
				],
				goods: [{
						name: "高端智能手机",
						price: "5999",
						image: "http://1.94.233.8:19000/education-bucket/ec4ea3ac-bfca-47bd-9fca-3d9ce099b115.jpg"
					},
					{
						name: "笔记本电脑",
						price: "6999",
						image: "https://via.placeholder.com/120/FF8879/FFFFFF?text=电脑"
					}
				]

			};
		},

		methods: {
			onTabChange(index) {
				this.current = index;
			},
			onSearch() {
				uni.$u.toast('搜索功能可自行扩展');
			},
			goToDetail(item) {
				uni.navigateTo({ url: '/pages/shop-details/shop-details' });
			}
		}
	};
</script>

<style scoped>
	.shop-home-page {
		min-height: 100vh;
		background: #2563eb;
		position: relative;
	}

	.top-section {
		position: fixed;
		left: 0;
		top: 0;
		right: 0;
		height: 80px;
		background: #2563eb;
		z-index: 20;
		display: flex;
		align-items: flex-end;
		justify-content: center;
	}

	.search-bar-top {
		width: 80%;
		margin-bottom: 12px;
	}

	.u-search-custom {
		width: 100%;
	}

	:deep(.u-search__content) {
		border-radius: 20px !important;
		background: #fff !important;
		box-shadow: 0 2px 8px rgba(44, 87, 246, 0.08);
	}

	:deep(.u-search__action) {
		margin-left: 4px !important;
		padding: 0 10px !important;
		height: 28px !important;
		min-width: 40px !important;
		font-size: 13px !important;
		border-radius: 14px !important;
	}

	.main-section {
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		top: 80px;
		background: #f6f8fc;
		border-top-left-radius: 10px;
		border-top-right-radius: 10px;
		box-shadow: 0 -8px 32px rgba(37, 99, 235, 0.06);
		display: flex;
		flex-direction: row;
		z-index: 10;
		height: calc(100vh - 80px);
	}

	.category-bar {
		width: 70px;
		background: #f6f8fc;
		border-top-left-radius: 24px;
		border-bottom-left-radius: 24px;
		/* padding-top: 20px; */
		display: flex;
		flex-direction: column;
		align-items: flex-start;
		box-shadow: 2px 0 8px rgba(37, 99, 235, 0.04);
		border-right: 1px solid #e5e7eb;
	}

	.category-item {
		padding: 18px 0 18px 20px;
		font-size: 13px;
		color: #b0b0b0;
		cursor: pointer;
		border-radius: 0;
		margin-bottom: 8px;
		text-align: center;
		transition: background 0.2s, color 0.2s;
		display: block;
		background: #f6f8fc;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.category-item.active {
		background: #fff;
		color: #111;
		font-weight: bold;
	}

	.content-bar {
		flex: 1;
		display: flex;
		flex-direction: column;
		padding: 24px 0 0 0;
		overflow: hidden;
		background: #f6f8fc;
	}

	.goods-scroll {
		flex: 1;
		height: 100%;
		overflow-y: auto;
	}

	.goods-list {
		display: flex;
		flex-direction: column;
		gap: 0;
		padding: 0 16px 20px 16px;
	}

	.goods-card {
		background: #fff;
		border-radius: 12px;
		box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
		display: flex;
		flex-direction: row;
		align-items: center;
		padding: 8px 8px 8px 0;
		margin-bottom: 0;
		min-height: 90px;
	}

	.goods-img {
		width: 100px;
		height: 75px;
		border-radius: 8px;
		margin-right: 12px;
		background: #f2f2f2;
		object-fit: cover;
	}

	.goods-side {
		display: flex;
		flex-direction: column;
		align-items: flex-end;
		justify-content: space-between;
		min-width: 120px;
		height: 75px;
		padding: 0 8px 0 0;
	}

	.goods-title {
		font-size: 15px;
		font-weight: bold;
		color: #222;
		margin-bottom: 0;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.goods-price {
		font-size: 14px;
		color: #2C57F6;
		font-weight: bold;
		margin: 0;
	}

	.buy-btn {
		width: 30rpx;
		height: 30px;
		font-size: 15px;
		box-sizing: border-box;
		padding: 0;
		margin-top: 0;
	}

	.goods-divider {
		height: 1px;
		background: #f2f2f2;
		margin: 0 0 0 70px;
	}
</style>